Q:

How to define a two dimensional array during run time in Visual Studio C++ 11?

I am trying to compile ORBSLAM2 on Windows with Visual Studio 2015 vc14 x64 compiler. The project was originally developed for GNU GCC. I now have the following issue:
// Compute distances between them
const size_t N = vDescriptors.size();

float aDistances[N][N];
for(size_t i=0;i<N;i++) {
    aDistances[i][i]=0;
    for(size_t j=i+1;j<N;j++) {
        int distij = ORBmatcher::DescriptorDistance(vDescriptors[i],vDescriptors[j]);
        aDistances[i][j]=distij;
        aDistances[j][i]=distij;
    }
}

I get the this error while compiling:

C2131 expression did not evaluate to a constant

... on this line of code:
const size_t N = vDescriptors.size();

Subsequently the two dimensional array definition fails too (float Distances[N][N];).
What's the best way to solve this in Visual-C++ ?
UPDATE: Here's the complete function code:
void MapPoint::ComputeDistinctiveDescriptors() {

    // Retrieve all observed descriptors
    vector<cv::Mat> vDescriptors;
    map<KeyFrame*,size_t> observations;

    {
        unique_lock<mutex> lock1(mMutexFeatures);
        if(mbBad)
            return;
        observations=mObservations;
    }

    if(observations.empty())
        return;

    vDescriptors.reserve(observations.size());

    for(map<KeyFrame*,size_t>::iterator mit=observations.begin(), mend=observations.end(); mit!=mend; mit++) {
        KeyFrame* pKF = mit->first;
        if(!pKF->isBad())
            vDescriptors.push_back(pKF->mDescriptors.row(mit->second));
    }

    if(vDescriptors.empty())
        return;

    // Compute distances between them
    const size_t N = vDescriptors.size();

    float aDistances[N][N];
    for(size_t i=0;i<N;i++) {
        aDistances[i][i]=0;
        for(size_t j=i+1;j<N;j++) {
            int distij = ORBmatcher::DescriptorDistance(vDescriptors[i],vDescriptors[j]);
            aDistances[i][j]=distij;
            aDistances[j][i]=distij;
        }
    }

    // Take the descriptor with least median distance to the rest
    int BestMedian = INT_MAX;
    int BestIdx = 0;
    for(size_t i=0;i<N;i++) {
        vector<int> vDists(aDistances[i], aDistances[i]+N);
        sort(vDists.begin(),vDists.end());
        int median = vDists[0.5*(N-1)];
        if(median<BestMedian) {
            BestMedian = median;
            BestIdx = i;
        }
    }

    {
        unique_lock<mutex> lock(mMutexFeatures);
        mDescriptor = vDescriptors[BestIdx].clone();
    }
}

A:

Your Problem
You tried to create a 2D array on the stack (this is not standard C++, even though it might work on some compilers). For this the size needs to be know at compile time, which is not the case as you call size() on an object which likely is not a constexpr.
QUICK FIX
A quick fix that works out of the box is to just allocate the memory on the heap (do not forget to delete array later on) by doing
float** aDistances = new float[N][N];

The deletion can be done in a function which looks like this
template <typename T>
void delete2DArray(T** ptr, size_t NumRows)
{
    for (size_t i = 0; i < NumRows; i++)
    {
        delete[] ptr[i];
    }
    delete[] ptr;
}

FIX
You will haveto use dynamic memory allocation. For this you can try the following approach by adding a wrapper class around std::vector (this should be possible as you said the scope is very manageable)
template <typename T>
class Array2D
{
public:
    Array2D(size_t numrows, size_t numcols) :
        rows(numrows), columns(numcols), array2d(rows * columns)
    {}

    T& operator()(size_t row, size_t column)
    {
        return array2d[row * columns + column]; 
    }

    const T& operator()(size_t row, size_t column) const
    {
        return array2d[row * columns + column];
    }

    T* getRow(size_t row)
    {
        return &array2d[row * columns];
    }

private:
    size_t rows;
    size_t columns;
    std::vector<T> array2d;
};

Than you have to modify your code like this:
// Compute distances between them
const size_t N = vDescriptors.size();

Array2D<float> aDistances(N,N);
for (size_t i = 0; i < N; i++) {
    aDistances(i,i) = 0;
    for (size_t j = i + 1; j < N; j++) {
        int distij = ORBmatcher::DescriptorDistance(vDescriptors[i], vDescriptors[j]);
        aDistances(i,j) = distij ;
        aDistances(j,i) = distij ;
    }
}

As you can see the syntax to access elements has slightly changed [x][y] -> (x,y).
EDIT
As the OP has modified the question, I have noticed that the Distances is used a second time which needs attention as well. For this you will have to add a getColumn method (see above) to the Array2D class. Than you further have to modify
// Take the descriptor with least median distance to the rest
int BestMedian = INT_MAX;
int BestIdx = 0;
for(size_t i=0;i<N;i++) {
    vector<int> vDists(aDistances.getRow()[i], aDistances.getRow()[i]+N);
    sort(vDists.begin(),vDists.end());
    int median = vDists[0.5*(N-1)];
    if(median<BestMedian) {
        BestMedian = median;
        BestIdx = i;
    }
}

NOTE: I am not perfectly sure if I got it right -- maybe you have to get a 
columns instead of a rows (too late to think straight). If this is the case you should also change the memory layout of the Array2D class, i.e. sorting the elements differently in the underlaying 1D-Vector.

