Mat assignment is inconsistent with roi technique. So, replace currentBuffer with a getCurrentBuffer() function and useROI variable.