Dynamic configured thumbnails are disappearing with 404

Hello.

I have created document template that was desired to allow user to specify thumbnail size dynamically, next to Image editable.
Everything seem to work fine but after moving to production with enabled Full page cache thumbnails are disappearing after a while with 404 not found error.
My template code

{% set width = pimcore_input('imgWidth', { placeholder: "Image width", width: 160 }) %}
{% set height = pimcore_input('imgHeight', { placeholder: "Image Height", width: 160 }) %}
<div class="container">
{% if editmode %}
    <div class="alert alert-warning">
        Image Width:{{ width|raw }} 
        Image Height:{{ height|raw }}
        {{ pimcore_image('richImage') }}
    </div>
{% else %}
    <img src="{{ pimcore_image('richImage').getThumbnail({ 'width': width.getData(), 'height': height.getData()}) }}"
         alt="{{ pimcore_image('richImage').getAlt() }}">
{% endif %}
</div>

I am aware of how thumbnails are generated. (what is mentioned here https://pimcore.com/docs/5.x/Development_Documentation/Assets/Working_with_Thumbnails/Image_Thumbnails.html#page_Dynamic-Generation-on-Request)
but how can I fix my solution to make it work properly? Is it possible to allow user to specify thumbnail size in editmode, next to image editable?

Can anyone help me with solving that issue?