     /*float * hCorr = (float *)malloc(corrSize);
     cutilSafeCall(cudaMemcpy(hCorr, d_corr, corrSize, cudaMemcpyDeviceToHost));
 
-    for (int i = 0; i < 16; i++) {
+    for (int i = 32; i < 64; i++) {
         cout << i << " ";
-        for (int j = 0; j < 32; j++) {
+        for (int j = 0; j < 16; j++) {
             cout << j << "[" << hCorr[i * size2 + j] << "]";
         }
         cout << endl;
     }
     cout << endl;
-    //free(hCorr);//*/
+    free(hCorr);//*/
 
     timings.tCalcCorrelation = clock() - myTime;
     myTime = clock();
 
     //calcBestCorr <<< blocksPerGrid, threadsPerBlock >>> (d_corr, d_bestCorr1, d_bestCorr2, points1.size(), points2.size());
     dim3 dimBlockBestCorrX(BEST_CORR_Y, BEST_CORR_X);
-    dim3 dimGridBestCorrX(size1 / BEST_CORR_Y, 1);
+    dim3 dimGridBestCorrX(size2 / BEST_CORR_Y, 1);
     bestCorrX <<< dimGridBestCorrX, dimBlockBestCorrX >>> (d_corr, d_bestCorr2, size1, size2);
     cudaThreadSynchronize();
 
+    dim3 dimBlockBestCorrY(BEST_CORR_X, BEST_CORR_Y);
+    dim3 dimGridBestCorrY(1, size1 / BEST_CORR_Y);
+    bestCorrY <<< dimGridBestCorrY, dimBlockBestCorrY >>> (d_corr, d_bestCorr1, size1, size2);
+    cudaThreadSynchronize();
+
     timings.tCalcBestCorr = clock() - myTime;
     myTime = clock();
 
-    int * bestCorr2 = (int *)malloc(size1 * sizeof(int));
-    cutilSafeCall(cudaMemcpy(bestCorr2, d_bestCorr2, size1 * sizeof(int), cudaMemcpyDeviceToHost));
-
-    for (int i = 0; i < points2.size(); i++) {
-        cout << "[" << bestCorr2[i] << "]";
+    /*int * bestCorr1 = (int *)malloc(size1 * sizeof(int));
+    cutilSafeCall(cudaMemcpy(bestCorr1, d_bestCorr1, size1 * sizeof(int), cudaMemcpyDeviceToHost));
+
+    for (int i = 0; i < points1.size(); i++) {
+        cout << i << " [" << bestCorr1[i] << "]";
     }
     cout << endl;    
-    free(bestCorr2);//*/
-
-    /*blocksPerGrid = ((points1.size() - 1) / threadsPerBlock) + 1;
+    free(bestCorr1);//*/
+
+    blocksPerGrid = ((points1.size() - 1) / threadsPerBlock) + 1;
     calcMatches <<< blocksPerGrid, threadsPerBlock >>> (d_bestCorr1, d_bestCorr2, d_matches, points1.size());
     cudaThreadSynchronize();
 

    for (int i = 0; i < points1.size(); i++)
        matches.push_back(h_matches[i]);

    timings.tMemCpy = clock() - myTime;*/
    myTime = clock();
    
    cutilSafeCall(cudaFree(d_m1));

}

__global__
void bestCorrX(float * corr, int * bestCorr2, int size1, int size2) {
    __shared__ float partialComp[BEST_CORR_X][BEST_CORR_Y];
    __shared__ int partialIdx[BEST_CORR_X][BEST_CORR_Y];

