diff --git a/libavfilter/vf_deshake.c b/libavfilter/vf_deshake.c
index 138c25d..efff390 100644
--- a/libavfilter/vf_deshake.c
+++ b/libavfilter/vf_deshake.c
@@ -294,8 +294,8 @@ static void find_motion(DeshakeContext *deshake, uint8_t *src1, uint8_t *src2,
     double p_x, p_y;
 
     // Reset counts to zero
-    for (x = 0; x < deshake->rx * 2 + 1; x++) {
-        for (y = 0; y < deshake->ry * 2 + 1; y++) {
+    for (x = 0; x < deshake->rx * 2; x++) {
+        for (y = 0; y < deshake->ry * 2; y++) {
             counts[x][y] = 0;
         }
     }
