     unsigned int bx = blockIdx.x;
     unsigned int by = blockIdx.y;
 
+    unsigned int mPos = bx * MEAN_SDV_THREADS + ty;
+    unsigned int descPos = (bx * (MEAN_SDV_THREADS) + ty) * SURF_DESCRIPTOR_SIZE + tx;
+
     if (tx == 0) {
-        mean1[ty] = m1[bx * MEAN_SDV_THREADS + ty];
-        mean2[ty] = m2[bx * MEAN_SDV_THREADS + ty];
+        mean1[ty] = m1[mPos];
+        mean2[ty] = m2[mPos];
     }
     __syncthreads();
 
-    partialSum1[ty][tx] = (desc1[(bx * (MEAN_SDV_THREADS) + ty) * SURF_DESCRIPTOR_SIZE + tx] - mean1[ty]) *
-                          (desc1[(bx * (MEAN_SDV_THREADS) + ty) * SURF_DESCRIPTOR_SIZE + tx] - mean1[ty]);
-    partialSum2[ty][tx] = (desc2[(bx * (MEAN_SDV_THREADS) + ty) * SURF_DESCRIPTOR_SIZE + tx] - mean2[ty]) *
-                          (desc2[(bx * (MEAN_SDV_THREADS) + ty) * SURF_DESCRIPTOR_SIZE + tx] - mean2[ty]);
+    float sub1 = desc1[descPos] - mean1[ty];
+    float sub2 = desc2[descPos] - mean2[ty];
+
+    partialSum1[ty][tx] = sub1 * sub1;
+    partialSum2[ty][tx] = sub2 * sub2;
+    
     for (unsigned int stride = blockDim.x>>1; stride > 0; stride >>= 1) {
         __syncthreads();
 

        }
        cout << endl;
    }
    free(hCorr);*/

    timings.tCalcCorrelation = clock() - myTime;
    myTime = clock();

    __syncthreads();

    if (tx == 0) {
        sdv1[mPos] = sqrt(partialSum1[ty][0] / SURF_DESCRIPTOR_SIZE);
        sdv2[mPos] = sqrt(partialSum2[ty][0] / SURF_DESCRIPTOR_SIZE);
    }       
}

__global__
