Combining your command with the command from How do I convert a video to GIF using ffmpeg, with reasonable quality?:
ffmpeg -i word.mp4 -i word.matte.mp4 -filter_complex "[1][0]scale2ref[mask][main];[main][mask]alphamerge,fps=10,scale=320:-1,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse" output.gif
Note the removal of -c:v qtrle
. You can't put QuickTime Animation RLE video into GIF output.
If you want a background photo combine command from How to overlay with ffmpeg?
ffmpeg -i word.mp4 -i word.matte.mp4 -i background.jpg -filter_complex "[1][0]scale2ref[mask][main];[main][mask]alphamerge[fg];[2][fg]overlay=(main_w-overlay_w)/2:(main_h-overlay_h)/2:format=auto,fps=10,scale=320:-1,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse" output.gif