     __syncthreads();
 
     for (int k = threadIdx.x; k < 2048; k += 1024) {
-      if (minneighbor[k] < 10000) {
+      if (minneighbor[k] < nump) {
           // Restore subpixel component
           float octsub = fabs(*(float*)(&kpts[minneighbor[k]].octave));
           int octave = (int)octsub;

  upper *= 2048;

  int offset = 0;
  for (short i = threadIdx.x; i < upper; i += 2 * FilterExtremaThreads) {
    minneighbor[threadIdx.x] =
        i >= nump ? 10001 : (memberarray[i] < 0 ? 10001 : (kpts[memberarray[i]].size < 0 ? 10001 : memberarray[i]));
    minneighbor[threadIdx.x + 1024] =
        i + 1024 >= nump ? 10001
                         : (memberarray[i + 1024] < 0 ? 10001 : (kpts[memberarray[i+1024]].size < 0 ? 10001 : memberarray[i+1024]));

    __syncthreads();


    offset += 2048;

    // How many did we add?
    if (minneighbor[2047] < nump) {
      curridx[0] += 2048;
    } else {
      if (minneighbor[1024] < nump) {
        if (threadIdx.x < 1023 && minneighbor[1024 + threadIdx.x] < nump &&
            minneighbor[1024 + threadIdx.x + 1] == nump+1) {
          curridx[0] += 1024 + threadIdx.x + 1;
        }
      } else {
        if (minneighbor[threadIdx.x] < nump &&
            minneighbor[threadIdx.x + 1] == nump+1) {
          curridx[0] += threadIdx.x + 1;
        }
      }
