Tweak scoping rules in instance generation

Variable names in the instance head should be propagated as parameters
to the methods, just like other parameters.

Fixes #956