BUG: Fix Coverity defects for LBFGS-B tests

This patch addresses the following coverity defects:
** CID 1186282
** CID 1186283

They are related on DeformableRegistration4&12 examples.
The cause of deffects was unchecked dynamic_cast.

Change-Id: Ifaa4211b1b2f07f6d8a30290428a31310d294791
Merge topic 'lbfgs-coverity'

d51263a3 BUG: Fix Coverity defects for LBFGS-B tests