fdo#39440 reduce scope of local variables

This addresses some cppcheck warnings.

Change-Id: Ib16e4ecc0e0c43b2c1fb527eb0668a960ae9756e
Reviewed-on: https://gerrit.libreoffice.org/13513
Reviewed-by: Noel Grandin <noelgrandin@gmail.com>
Tested-by: Noel Grandin <noelgrandin@gmail.com>