fdo#39440 reduce scope of local variables

This addresses some cppcheck warnings.

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