BUG: optimize: fix issue with incorrect use of closure for slsqp.

Closes gh-4240.
Merge pull request #4248 from rgommers/fix-slsqp-issue-4240

BUG: optimize: fix issue with incorrect use of closure for slsqp.