Solved the problem myself:
My original function was based on the example
which I got from the 2019a version. This example differs to the one from the 2016b version. So I took my function code and put it into the old versions example. This old example differs in various code lines among others the one in the error message.