Fix memory leak in scan related to the input and output storage of the inner function.

This fixes a memory exhaustion error on the GPU for the recurrent LSTM speech model.

It was also only lightly tested as it's really late.  Sorry if there are stupid typos or something like that.
I've updated the comment to say that we mimick Function.__call__.  But I think we should keep the check for allow_gc since it might introduce unwanted synchronization points if we always do it.

Right now it checks the allow_gc property of the inner scan function, so a future option to disable the gc only there would affect it.  I would check to global option if I knew how.