fixes handling of empty matrices in some functions (#11634) * a part of PR #11416 by Yuki Takehara * moved the empty mat check in Mat::copyTo() * fixed some test failures