Bfmatcher fix

this is alternative variant of #3025 without any changes in core