Fixes buy with iterator undefined behaviour in downSample implemntation.