Refactorized detection of function usage in CheckUnusedFunction, fixed #5358