Fix for #1496: Backend error with higher order functions taking a parameter function that has at least 5 parameters

This needs a proper review by @tombentley
Test for #1496: Backend error with higher order functions taking a parameter function that has at least 5 parameters