fdo#39440 reduce scope of local variables

This addresses some cppcheck warnings.

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