Reducing the memory used by the block matching algorithm