     unsigned int bx = blockIdx.x;
     unsigned int by = blockIdx.y;
 
-    partialSum1[ty][tx] = desc1[(bx * (MEAN_SDV_THREADS) + ty) * SURF_DESCRIPTOR_SIZE + tx];
-    partialSum2[ty][tx] = desc2[(bx * (MEAN_SDV_THREADS) + ty) * SURF_DESCRIPTOR_SIZE + tx];
+    unsigned int descPos = (bx * (MEAN_SDV_THREADS) + ty) * SURF_DESCRIPTOR_SIZE + tx;
+    unsigned int mPos = bx * MEAN_SDV_THREADS + ty;
+
+    partialSum1[ty][tx] = desc1[descPos];
+    partialSum2[ty][tx] = desc2[descPos];
 
     for (unsigned int stride = blockDim.x>>1; stride > 0; stride >>= 1) {
         __syncthreads();

    __syncthreads();

    if (tx == 0) {
        m1[bx * MEAN_SDV_THREADS + ty] = partialSum1[ty][0] / SURF_DESCRIPTOR_SIZE;        
        m2[bx * MEAN_SDV_THREADS + ty] = partialSum2[ty][0] / SURF_DESCRIPTOR_SIZE;
    }    
}


    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[mPos];
        mean2[ty] = m2[mPos];
    }
    __syncthreads();

    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();

