Rewritten compareMatrices
The function stops checking a cell once its difference is less than the threshold.