A couple of fixes for optimize/trust-region

As discussed in scipy/scipy#526.

If you agree with these changes, you can merge this branch into your trust-region branch and push the result back so that the PR on scipy gets updated. E.g.:

```
git checkout trust-region # if needed
git pull https://github.com/dlax/scipy trust-region-fix
git push origin trust-region
```

Thanks.