 #define in(i, j) in[(i)*w + (j)]
 #define out(i, j) out[(i)*w + (j)]
 #define FOR_WINDOW(i2, j2, i, j, h, w, wd) \
-	for (i2 = max(0, i - wd); min(h, i2 < i + wd); i2++) \
-		for (j2 = max(0, j - wd); min(w, j2 < j + wd); j2++)
+	for (i2 = max(0, i - wd); i2 < min(h, i + wd); i2++) \
+		for (j2 = max(0, j - wd); j2 < min(w, j + wd); j2++)
 
 __global__ static void updateMotion(
 		bool *m, uint32_t *d, int h, int w) {

	bool **dmotions;
} KernelContext;

__device__ uint32_t lum(uint32_t u) {
	int r = u & 0xff,
		g = (u >> 8) & 0xff,
		b = (u >> 16) & 0xff;

	return sqrt(double(r * r + g * g + b * b));
}
*/
__device__ __host__ inline static uint32_t distance(int32_t u, int32_t v) {
	return abs(int(lum(u)) - int(lum(v)));
}

